package com.ruoyi.web.controller.business;

import com.ruoyi.business.domain.WxFeedback;
import com.ruoyi.business.service.IWxFeedbackService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 微信用户意见反馈Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/business/feedback")
public class WxFeedbackController extends BaseController
{
    @Autowired
    private IWxFeedbackService wxFeedbackService;

    /**
     * 查询微信用户意见反馈列表
     */
    @PreAuthorize("@ss.hasPermi('business:feedback:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxFeedback wxFeedback)
    {
        startPage();
        List<WxFeedback> list = wxFeedbackService.selectWxFeedbackList(wxFeedback);
        return getDataTable(list);
    }

    /**
     * 导出微信用户意见反馈列表
     */
    @PreAuthorize("@ss.hasPermi('business:feedback:export')")
    @Log(title = "微信用户意见反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxFeedback wxFeedback)
    {
        List<WxFeedback> list = wxFeedbackService.selectWxFeedbackList(wxFeedback);
        ExcelUtil<WxFeedback> util = new ExcelUtil<WxFeedback>(WxFeedback.class);
        util.exportExcel(response, list, "微信用户意见反馈数据");
    }

    /**
     * 获取微信用户意见反馈详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:feedback:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wxFeedbackService.selectWxFeedbackById(id));
    }

    /**
     * 新增微信用户意见反馈
     */
    @PreAuthorize("@ss.hasPermi('business:feedback:add')")
    @Log(title = "微信用户意见反馈", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxFeedback wxFeedback)
    {

        return toAjax(wxFeedbackService.insertWxFeedback(wxFeedback));
    }

    /**
     * 修改微信用户意见反馈
     */
    @PreAuthorize("@ss.hasPermi('business:feedback:edit')")
    @Log(title = "微信用户意见反馈", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxFeedback wxFeedback)
    {
        return toAjax(wxFeedbackService.updateWxFeedback(wxFeedback));
    }

    /**
     * 处理微信用户意见反馈
     */
    @PreAuthorize("@ss.hasPermi('business:feedback:edit')")
    @Log(title = "处理微信用户意见反馈", businessType = BusinessType.UPDATE)
    @PutMapping("/handle")
    public AjaxResult handle(@RequestBody WxFeedback wxFeedback)
    {
        // 验证必要参数
        if (wxFeedback.getId() == null) {
            return error("反馈ID不能为空");
        }
        if (wxFeedback.getStatus() == null) {
            return error("处理状态不能为空");
        }
        
        wxFeedback.setUpdateBy(getUsername());
        return toAjax(wxFeedbackService.updateWxFeedback(wxFeedback));
    }

    /**
     * 删除微信用户意见反馈
     */
    @PreAuthorize("@ss.hasPermi('business:feedback:remove')")
    @Log(title = "微信用户意见反馈", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wxFeedbackService.deleteWxFeedbackByIds(ids));
    }
} 